package com.situ.studentmanagement.controller;

import com.situ.studentmanagement.dao.AfficheMapper;
import com.situ.studentmanagement.dao.GoodsMapper;
import com.situ.studentmanagement.model.Affiche;
import com.situ.studentmanagement.model.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

import java.util.List;

import static com.situ.studentmanagement.Constants.*;

/**
 * Created by baba on 2016/8/3.
 */
@Controller //表示这个类是一个Controller，于是当请求路径 / 时，这个Contrller的实例被自动创建
@RequestMapping("/logon") //这个controller对应到路径 /
public class logon {
    @Autowired
    AfficheMapper afficheMapper;
    @Autowired
    GoodsMapper goodsMapper;

    @RequestMapping("/openleft")
    public String register(Model model, HttpSession session){
        return "left";
    }
    @RequestMapping("/getout")
    public String getout(Model model, HttpSession session){
        session.setAttribute(USER_ID,null);
        session.setAttribute(USER_NAME,null);
        session.setAttribute(USER_ID,null);
        session.setAttribute(USER_PASSWORD,null);
        session.setAttribute(ORDER_NUMBER,null);
        if(session.getAttribute(USER_ID)!=null){
            model.addAttribute("name",session.getAttribute(USER_NAME));
            model.addAttribute("message",1);
        }
        List<Affiche> affiches=afficheMapper.selectAllAffiche();
        model.addAttribute("affiches",affiches);
        //查询说有的菜品
        List<Goods> goodses=goodsMapper.selectAllGoods();
        model.addAttribute("goods",goodses);
        return "index";
    }

}
